// Copyright DustedPixels.com 2008. All rights reserved.

package com.dustedpixels.jasmin.cpu;

import com.dustedpixels.jasmin.memory.Memory;

/**
 * @author micapolos@gmail.com (Michal Pociecha-Los)
 */
public final class MemoryImpl implements Memory {
  private final byte[] data;
  private final int mask;

  public MemoryImpl(int addressBits) {
    this.data = new byte[1 << addressBits];
    this.mask = data.length - 1;
  }

  public byte read(int address) {
    return data[address & mask];
  }

  public void write(int address, byte value) {
    data[address & mask] = value;
  }  
}
